from rest_framework import serializers
from .models import BookingPost, BookingPostImage
from django.contrib.auth import get_user_model

User = get_user_model()


class UserBriefSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['id', 'username', 'avatar_url']  # 确保 User 模型有 avatar 字段


class BookingPostImageSerializer(serializers.ModelSerializer):
    class Meta:
        model = BookingPostImage
        fields = ['image']


class BookingPostSerializer(serializers.ModelSerializer):
    user = UserBriefSerializer(read_only=True)
    images = BookingPostImageSerializer(many=True,required=False)

    class Meta:
        model = BookingPost
        fields = ['id', 'user', 'title', 'description',
                  'camera_info', 'price_per_hour', 'latitude',
                  'longitude', 'created_at', 'images'
                  ]
